package com.daxue.common.http.utils;

/**
 * @author daxue0929
 * @date 2022/4/7
 */

public class RateLimiterConfig {
    private long maxPermits;
    private long intervalMillis;
    private int grantFactor = 0;

    private RateLimiterConfig() {
    }

    public static RateLimiterConfig newInstance() {
        return new RateLimiterConfig();
    }

    public long getMaxPermits() {
        return this.maxPermits;
    }

    public long getIntervalMillis() {
        return this.intervalMillis;
    }

    public int getGrantFactor() {
        return this.grantFactor;
    }

    public RateLimiterConfig setMaxPermits(final long maxPermits) {
        this.maxPermits = maxPermits;
        return this;
    }

    public RateLimiterConfig setIntervalMillis(final long intervalMillis) {
        this.intervalMillis = intervalMillis;
        return this;
    }

    public RateLimiterConfig setGrantFactor(final int grantFactor) {
        this.grantFactor = grantFactor;
        return this;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof RateLimiterConfig)) {
            return false;
        } else {
            RateLimiterConfig other = (RateLimiterConfig)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getMaxPermits() != other.getMaxPermits()) {
                return false;
            } else if (this.getIntervalMillis() != other.getIntervalMillis()) {
                return false;
            } else {
                return this.getGrantFactor() == other.getGrantFactor();
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof RateLimiterConfig;
    }

    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        long $maxPermits = this.getMaxPermits();
        result = result * 59 + (int)($maxPermits >>> 32 ^ $maxPermits);
        long $intervalMillis = this.getIntervalMillis();
        result = result * 59 + (int)($intervalMillis >>> 32 ^ $intervalMillis);
        result = result * 59 + this.getGrantFactor();
        return result;
    }

    public String toString() {
        return "RateLimiterConfig(maxPermits=" + this.getMaxPermits() + ", intervalMillis=" + this.getIntervalMillis() + ", grantFactor=" + this.getGrantFactor() + ")";
    }
}
